from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-02 14:03:06.682144
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 02, Aug, 2022
Time: 14:03:12
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.0054
Nobs: 736.000 HQIC: -50.3510
Log likelihood: 9299.99 FPE: 1.09291e-22
AIC: -50.5680 Det(Omega_mle): 9.67912e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297758 0.056033 5.314 0.000
L1.Burgenland 0.107756 0.037002 2.912 0.004
L1.Kärnten -0.106911 0.019612 -5.451 0.000
L1.Niederösterreich 0.207298 0.077287 2.682 0.007
L1.Oberösterreich 0.108156 0.075499 1.433 0.152
L1.Salzburg 0.254230 0.039548 6.428 0.000
L1.Steiermark 0.042327 0.051604 0.820 0.412
L1.Tirol 0.108796 0.041866 2.599 0.009
L1.Vorarlberg -0.062294 0.036030 -1.729 0.084
L1.Wien 0.047925 0.066740 0.718 0.473
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057224 0.117097 0.489 0.625
L1.Burgenland -0.032026 0.077327 -0.414 0.679
L1.Kärnten 0.047052 0.040985 1.148 0.251
L1.Niederösterreich -0.175831 0.161514 -1.089 0.276
L1.Oberösterreich 0.407716 0.157777 2.584 0.010
L1.Salzburg 0.287882 0.082649 3.483 0.000
L1.Steiermark 0.107904 0.107842 1.001 0.317
L1.Tirol 0.311283 0.087491 3.558 0.000
L1.Vorarlberg 0.025722 0.075296 0.342 0.733
L1.Wien -0.029552 0.139474 -0.212 0.832
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188718 0.028741 6.566 0.000
L1.Burgenland 0.090197 0.018980 4.752 0.000
L1.Kärnten -0.008930 0.010060 -0.888 0.375
L1.Niederösterreich 0.259341 0.039643 6.542 0.000
L1.Oberösterreich 0.139960 0.038726 3.614 0.000
L1.Salzburg 0.045595 0.020286 2.248 0.025
L1.Steiermark 0.021457 0.026469 0.811 0.418
L1.Tirol 0.093348 0.021474 4.347 0.000
L1.Vorarlberg 0.055839 0.018481 3.021 0.003
L1.Wien 0.115607 0.034233 3.377 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109267 0.029181 3.744 0.000
L1.Burgenland 0.045824 0.019270 2.378 0.017
L1.Kärnten -0.014061 0.010214 -1.377 0.169
L1.Niederösterreich 0.188654 0.040250 4.687 0.000
L1.Oberösterreich 0.301766 0.039319 7.675 0.000
L1.Salzburg 0.109716 0.020596 5.327 0.000
L1.Steiermark 0.104752 0.026875 3.898 0.000
L1.Tirol 0.105846 0.021803 4.855 0.000
L1.Vorarlberg 0.068625 0.018764 3.657 0.000
L1.Wien -0.021115 0.034757 -0.607 0.544
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126413 0.053196 2.376 0.017
L1.Burgenland -0.049930 0.035129 -1.421 0.155
L1.Kärnten -0.040850 0.018619 -2.194 0.028
L1.Niederösterreich 0.167618 0.073374 2.284 0.022
L1.Oberösterreich 0.139812 0.071676 1.951 0.051
L1.Salzburg 0.289036 0.037546 7.698 0.000
L1.Steiermark 0.036054 0.048991 0.736 0.462
L1.Tirol 0.163440 0.039746 4.112 0.000
L1.Vorarlberg 0.101722 0.034206 2.974 0.003
L1.Wien 0.068759 0.063361 1.085 0.278
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055422 0.042289 1.311 0.190
L1.Burgenland 0.039437 0.027926 1.412 0.158
L1.Kärnten 0.051044 0.014802 3.449 0.001
L1.Niederösterreich 0.217059 0.058330 3.721 0.000
L1.Oberösterreich 0.295990 0.056981 5.195 0.000
L1.Salzburg 0.043834 0.029848 1.469 0.142
L1.Steiermark 0.001451 0.038947 0.037 0.970
L1.Tirol 0.143230 0.031597 4.533 0.000
L1.Vorarlberg 0.072336 0.027193 2.660 0.008
L1.Wien 0.080996 0.050370 1.608 0.108
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171752 0.050553 3.397 0.001
L1.Burgenland -0.002300 0.033384 -0.069 0.945
L1.Kärnten -0.062625 0.017694 -3.539 0.000
L1.Niederösterreich -0.080432 0.069729 -1.153 0.249
L1.Oberösterreich 0.191762 0.068116 2.815 0.005
L1.Salzburg 0.057803 0.035681 1.620 0.105
L1.Steiermark 0.235008 0.046558 5.048 0.000
L1.Tirol 0.498447 0.037772 13.196 0.000
L1.Vorarlberg 0.046498 0.032507 1.430 0.153
L1.Wien -0.053708 0.060214 -0.892 0.372
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163139 0.058242 2.801 0.005
L1.Burgenland -0.007755 0.038461 -0.202 0.840
L1.Kärnten 0.065900 0.020385 3.233 0.001
L1.Niederösterreich 0.201002 0.080333 2.502 0.012
L1.Oberösterreich -0.068363 0.078475 -0.871 0.384
L1.Salzburg 0.207761 0.041108 5.054 0.000
L1.Steiermark 0.123825 0.053638 2.309 0.021
L1.Tirol 0.072540 0.043516 1.667 0.096
L1.Vorarlberg 0.120490 0.037451 3.217 0.001
L1.Wien 0.123056 0.069371 1.774 0.076
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359755 0.033487 10.743 0.000
L1.Burgenland 0.007264 0.022113 0.329 0.743
L1.Kärnten -0.023680 0.011721 -2.020 0.043
L1.Niederösterreich 0.215731 0.046188 4.671 0.000
L1.Oberösterreich 0.198839 0.045120 4.407 0.000
L1.Salzburg 0.043502 0.023635 1.841 0.066
L1.Steiermark -0.013314 0.030840 -0.432 0.666
L1.Tirol 0.104882 0.025020 4.192 0.000
L1.Vorarlberg 0.070906 0.021533 3.293 0.001
L1.Wien 0.038130 0.039886 0.956 0.339
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039504 0.139499 0.191268 0.150951 0.117390 0.103228 0.063210 0.216503
Kärnten 0.039504 1.000000 -0.007581 0.132491 0.039230 0.094328 0.433100 -0.054027 0.097372
Niederösterreich 0.139499 -0.007581 1.000000 0.334438 0.141712 0.292848 0.094945 0.180056 0.313522
Oberösterreich 0.191268 0.132491 0.334438 1.000000 0.228248 0.324528 0.175742 0.164936 0.261243
Salzburg 0.150951 0.039230 0.141712 0.228248 1.000000 0.141954 0.112289 0.145018 0.124282
Steiermark 0.117390 0.094328 0.292848 0.324528 0.141954 1.000000 0.145693 0.137007 0.071385
Tirol 0.103228 0.433100 0.094945 0.175742 0.112289 0.145693 1.000000 0.111662 0.143234
Vorarlberg 0.063210 -0.054027 0.180056 0.164936 0.145018 0.137007 0.111662 1.000000 -0.000684
Wien 0.216503 0.097372 0.313522 0.261243 0.124282 0.071385 0.143234 -0.000684 1.000000